home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- cv.c - Address/time type conversion routines.
-
- Tim Heidmann, Silicon Graphics
-
- Created January 25, 1994
- Last Edit January 27, 1994
- */
-
- #include <stdio.h>
- #include <sys/time.h>
- #include "cv.h"
-
- #define FPS 30
- #define FPM 1800
- #define FPH 108000
-
- int cv_errno;
-
- int
- mc_convert(int fromType, int toType, ...) {
- int *arg;
- int *pFrame, iFrame;
- int h, m, s, f;
- char *cptr;
- char buf[64], buf2[64], *b, *c;
- int pad;
- struct timeval *tvp;
-
- cv_errno = 0;
- arg = &toType + 1;
- switch (toType) {
-
- case MC_NTSC_FRAME:
- if (fromType != MC_NTSC_TC) {
- cv_errno = CV_UNSUPPORTED; return -1; }
-
- cptr = (char *)(arg[0]);
- pFrame = (int *)(arg[1]);
-
- /* Remove all but numerics */
- for (b = buf, c = cptr; *c != '\0'; c++)
- if (*c >= '0' && *c <= '9') *(b++) = *c;
- *b = '\0';
-
- /* Pad to hhhhmmssff */
- strcpy(buf2, "0000000000");
- pad = 10 - strlen(buf);
- if (pad >= 0)
- strcpy(buf2 + pad, buf);
- else
- strcpy(buf2, buf - pad);
-
- /* Scan it! */
- sscanf(buf2, "%4d%2d%2d%2d", &h, &m, &s, &f);
- *pFrame = FPH * h + FPM * m + FPS * s + f;
- return 0;
-
-
- case MC_NTSC_TC:
- if (fromType != MC_NTSC_FRAME) {
- cv_errno = CV_UNSUPPORTED; return -1; }
-
- iFrame = arg[0];
- cptr = (char *)(arg[1]);
-
- if (iFrame < 0)
- cptr[0] = '\0';
- else {
- h = iFrame / FPH;
- iFrame -= h * FPH;
- m = iFrame / FPM;
- iFrame -= m * FPM;
- s = iFrame / FPS;
- iFrame -= s * FPS;
- sprintf(cptr, "%02d:%02d:%02d:%02d", h, m, s, iFrame);
- }
- return 0;
-
-
- case MC_TIME:
- if (fromType != MC_NTSC_FRAME) {
- cv_errno = CV_UNSUPPORTED; return -1; }
-
- iFrame = arg[0];
- tvp = (struct timeval *)(arg[1]);
- tvp->tv_sec = (int)(iFrame / NTSC_FRAMES_PER_SEC);
- tvp->tv_usec = NTSC_USEC_PER_FRAME *
- (iFrame - (int)(tvp->tv_sec * NTSC_FRAMES_PER_SEC));
- return 0;
-
-
- default:
- cv_errno = CV_UNSUPPORTED;
- return -1;
- }
- }
-